package com.jiantong.admin;


import com.jiantong.admin.interceptor.AdminLoginInterceptor;
import com.jiantong.web.core.CoreWebConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@EnableSwagger2 // 如果用到terminus的msg模块发短信需要把swagger配置关闭
@Configuration
@ComponentScan(
        basePackages = {
                "com.jiantong.admin",
        }
)
@Import({
        CoreWebConfiguration.class
})
@EnableWebMvc
@EnableAutoConfiguration
public class AdminConfiguration extends WebMvcConfigurerAdapter {

    private final AdminLoginInterceptor adminLoginInterceptor;

    @Autowired
    public AdminConfiguration(AdminLoginInterceptor adminLoginInterceptor) {
        this.adminLoginInterceptor = adminLoginInterceptor;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(adminLoginInterceptor);
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        if (!registry.hasMappingForPattern("/webjars/**")) {
            registry.addResourceHandler("/webjars/**").addResourceLocations(
                    "classpath:/static/");
        }
    }

}
